<template>
	<view class="wrap" style="height: calc(100vh - 190rpx);">
		<!-- 搜索栏和顶部导航栏 -->
		<scroll-view scroll-x="true" @scroll="scroll" class="scroll-view_H">
			<view class="search">
				<view class="search_content">
					<view class="search_content_center">
						<view class="search_logo">
							<image src="../../static/img/search.png"></image>
						</view>
						<view class="search_input">
							<input class="weui-input" @input="search_inputs" placeholder="请输入搜索内容" v-model="keyword" />
						</view>
					</view>
				</view>
			</view>
			<scroll-view scroll-x="true" @scroll="scroll" class="swich_tab">
				<view class="scroll-view-item_H">
					<view :class="currentTab==0?'on':''" data-current="0" @click="swichNav">已接单</view>
				</view>
				<view class="scroll-view-item_H">
					<view :class="currentTab==1?'on':''" data-current="1" @click="swichNav">已预约</view>
				</view>
				<view class="scroll-view-item_H">
					<view :class="currentTab==2?'on':''" data-current="2" @click="swichNav">已到达</view>
				</view>
				<view class="scroll-view-item_H">
					<view :class="currentTab==3?'on':''" data-current="3" @click="swichNav">已完成</view>
				</view>
			</scroll-view>
		</scroll-view>
		<!-- 订单内容部分 -->
		<swiper :current="currentTab" class="swiper-box" duration="300" @change="bindChange">
			<block>
				<!-- 已接单 内容 -->
				<swiper-item class="swip">
					<scroll-view scroll-y="true" @scrolltolower="scrobottom" @scrolltoupper="srctop">
						<block v-if="orderList.length>0">
							<view class="type_item" v-for="(item,index) in orderList" :key="index" @click="toDetails(item)">
								<view class="item_title">
									<view>订单号：</view>
									<view>{{ item.orderNo }}</view>
								</view>
								<view class="item_operation">
									<view class="item_content">
										<view class="item_info">
											<view class="name">
												<view class="name_content">
													<view>报修设备：</view>
													<view>{{ item.equipName }}</view>
												</view>
											</view>
											<view class="describe">
												<view class="describe_content">
													<view>
														报修问题：
														<text>{{ item.problemDescription }}</text>
													</view>
												</view>
											</view>
										</view>
									</view>
								</view>
								<!-- <view class="order_adress">
									<view class="order_adress_text" @click="to_map">
										<view>
											<image src="../../static/img/adress.png"></image>
										</view>
										<view>{{ item.iAddress }}</view>
									</view>
									<view class="order_adress_distance">距您{{ item.distance }}Km</view>
								</view> -->
								<view class="item_btn">
									<view @click.stop="to_confirm(item)">填写沟通详情</view>
								</view>
							</view>
						</block>
						<block v-if="orderList.length==0">
							<view class="not_yet">
								<image src="../../static/img/empty.png"></image>
							</view>
						</block>
					</scroll-view>
				</swiper-item>
				<!-- 配件确认 内容 -->
				<swiper-item class="swip">
					<scroll-view scroll-y="true" @scrolltolower="scrobottom">
						<block v-if="orderList.length>0">
							<view class="type_item" v-for="(item,index) in orderList" :key="index" @click="toDetails(item)">
								<view class="item_title">
									<view>订单号：</view>
									<view>{{ item.orderNo }}</view>
								</view>
								<view class="item_operation">
									<view class="item_content">
										<view class="item_info">
											<view class="name">
												<view class="name_content">
													<view>报修设备：</view>
													<view>{{ item.equipName }}</view>
												</view>
											</view>
											<view class="describe">
												<view class="describe_content">
													<view>
														报修问题：
														<text>{{ item.problemDescription }}</text>
													</view>
												</view>
											</view>
										</view>
									</view>
								</view>
								<view class="item_btn">
									<view @click.stop="to_local(item)">已到达</view>
								</view>
							</view>
						</block>
						<block v-if="orderList.length==0">
							<view class="not_yet">
								<image src="../../static/img/empty.png"></image>
							</view>
						</block>
					</scroll-view>
				</swiper-item>
				<!-- 维修中 内容 -->
				<!-- <swiper-item class="swip">
					<scroll-view scroll-y="true" @scrolltolower="scrobottom">
						<block v-if="orderList.length>0">
							<view class="type_item" v-for="(item,index) in orderList" :key="index">
								<view class="item_title" @click="toDetails">
									<view>订单号：</view>
									<view>{{ item.orderNo }}</view>
								</view>
								<view class="item_operation">
									<view class="item_content">
										<view class="item_info">
											<view class="name">
												<view class="name_content">
													<view>报修设备：</view>
													<view>{{ item.equipName }}</view>
												</view>
											</view>
											<view class="describe">
												<view class="describe_content">
													<view>
														报修问题：
														<text>{{ item.problemDescription }}</text>
													</view>
												</view>
											</view>
										</view>
									</view>
								</view>
								<view style="color: #5f6ed5;">等待后报价确认</view>
							</view>
						</block>
						<block v-if="orderList.length==0">
							<view class="not_yet">
								<image src="../../static/img/empty.png"></image>
							</view>
						</block>
					</scroll-view>
				</swiper-item> -->
				<!-- 费用确认 内容 -->
				<swiper-item class="swip">
					<scroll-view scroll-y="true" @scrolltolower="scrobottom">
						<block v-if="orderList.length>0">
							<view class="type_item" v-for="(item,index) in orderList" :key="index" @click="toDetails(item)">
								<view class="item_title">
									<view>订单号：</view>
									<view>{{ item.orderNo }}</view>
								</view>
								<view class="item_operation">
									<view class="item_content">
										<view class="item_info">
											<view class="name">
												<view class="name_content">
													<view>报修设备：</view>
													<view>{{ item.equipName }}</view>
												</view>
											</view>
											<view class="describe">
												<view class="describe_content">
													<view>
														报修问题：
														<text>{{ item.problemDescription }}</text>
													</view>
												</view>
											</view>
										</view>
									</view>
								</view>
								<view class="item_btn">
									<view @click.stop="to_repair(item)">维修分析</view>
								</view>
							</view>
						</block>
						<block v-if="orderList.length==0">
							<view class="not_yet">
								<image src="../../static/img/empty.png"></image>
							</view>
						</block>
					</scroll-view>
				</swiper-item>
				<!-- 已完成 内容 -->
				<swiper-item class="swip">
					<scroll-view scroll-y="true" @scrolltolower="scrobottom">
						<block v-if="orderList.length>0">
							<view class="type_item" v-for="(item,index) in orderList" :key="index" @click="toDetails(item)">
								<view class="item_title" @click="toDetails">
									<view>订单号：</view>
									<view>{{ item.orderNo }}</view>
								</view>
								<view class="item_operation">
									<view class="item_content">
										<view class="item_info">
											<view class="name">
												<view class="name_content">
													<view>报修设备：</view>
													<view>{{ item.equipName }}</view>
												</view>
											</view>
											<view class="describe">
												<view class="describe_content">
													<view>
														报修问题：
														<text>{{ item.problemDescription }}</text>
													</view>
												</view>
											</view>
										</view>
									</view>
								</view>
								<view class="item_btn">
									<view @click.stop="to_jd(item)">已完成</view>
								</view>
							</view>
						</block>
						<block v-if="orderList.length==0">
							<view class="not_yet">
								<image src="../../static/img/empty.png"></image>
							</view>
						</block>
					</scroll-view>
				</swiper-item>
			</block>
		</swiper>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				keyword: '', //搜索
				currentTab: 0, //tab切换
				orderList: [], //订单数据
				userId: '',
				type: '',
				pageSize:10
			}
		},
		methods: {
			scroll() {

			},
			to_local(item) {
				let obj = {
					id: item.id,
					orderNo: item.orderNo,
					orderStatus: 4,
					transferMessage: "",
					type: 4,
					workName: getApp().globalData.nickName
				}
				this.$newapi.updateOrder(obj).then(response => {
					if (response.code == 200) {
						const params = {
							keyword: '',
							page: 1,
							pageSize: 10,
						};
						this.$newapi.getOrderList(params).then((res) => {
							if (res.code == 200) {
								console.log(res);
								this.orderList = res.data.list.filter(item => item.orderStatus == 3)
								this.currentTab = 2
								const params = {
									keyword: '',
									page: 1,
									pageSize: 10,
								};
								this.$newapi.getOrderList(params).then((res) => {
									if (res.code == 200) {
										console.log(res);
										this.orderList = res.data.list.filter(item => item.orderStatus == 4)
									} else {
										toast(res.msg)
									}
								}).catch((err) => {
									console.log(err);
								});
							} else {
								toast(res.msg)
							}
						}).catch((err) => {
							console.log(err);
						});
					}
				})
			},
			// 搜索
			search_inputs(e) {
				this.keyword = e.detail.value
				const params = {
					keyword: this.keyword,
					page: 1,
					pageSize: 10,
				};
				this.$newapi.getOrderList(params).then((res) => {
					if (res.code == 200) {
						console.log(res);
						this.orderList = res.data.list.filter(item => item.orderStatus == this.currentTab+2)
					} else {
						toast(res.msg)
					}
				}).catch((err) => {
					console.log(err);
				});
			},
			// 填写沟通详情
			to_confirm(item) {
				uni.navigateTo({
					url: `/pagesIndex/receiving_orders/receiving_orders?orderItem=${JSON.stringify(item)}`
				});
			},
			toDetails(item){
				uni.navigateTo({
					url: `/pagesIndex/confirm_order/confirm_order?orderItem=${JSON.stringify(item)}&statusData=详情`
				});
			},
			// 订单完成
			to_jd(item) {
				uni.navigateTo({
					url: `/pagesIndex/receiving_orders/fittings_orders?orderItem=${JSON.stringify(item)}`
				});
			},
			// 填写维修分析
			to_repair(item) {
				uni.navigateTo({
					url: `/pagesIndex/receiving_orders/repairResults?orderItem=${JSON.stringify(item)}`
				});
			},
			// nav导航切换
			swichNav(e) {
				this.keyword = ''
				if (this.currentTab === e.target.dataset.current) {
					return false;
				} else {
					this.currentTab = e.target.dataset.current
				}
				// 已确认
				if (this.currentTab == 0) {
					this.type = ''
					const params = {
						keyword: '',
						page: 1,
						pageSize: 10,
					};
					this.$newapi.getOrderList(params).then((res) => {
						if (res.code == 200) {
							console.log(res);
							this.orderList = res.data.list.filter(item => item.orderStatus == 2)
						} else {
							toast(res.msg)
						}
					}).catch((err) => {
						console.log(err);
					});
				}
				// 已预约
				if (this.currentTab == 1) {
					this.type = ''
					const params = {
						keyword: '',
						page: 1,
						pageSize: 10,
					};
					this.$newapi.getOrderList(params).then((res) => {
						if (res.code == 200) {
							console.log(res);
							this.orderList = res.data.list.filter(item => item.orderStatus == 3)
						} else {
							toast(res.msg)
						}
					}).catch((err) => {
						console.log(err);
					});
				}
				// 已到达
				if (this.currentTab == 2) {
					this.type = ''
					const params = {
						keyword: '',
						page: 1,
						pageSize: 10,
					};
					this.$newapi.getOrderList(params).then((res) => {
						if (res.code == 200) {
							console.log(res);
							this.orderList = res.data.list.filter(item => item.orderStatus == 4)
						} else {
							toast(res.msg)
						}
					}).catch((err) => {
						console.log(err);
					});
				}
				// 已完成
				if (this.currentTab == 3) {
					this.type = ''
					const params = {
						keyword: '',
						page: 1,
						pageSize: 10,
					};
					this.$newapi.getOrderList(params).then((res) => {
						if (res.code == 200) {
							console.log(res);
							this.orderList = res.data.list.filter(item => item.orderStatus == 5)
						} else {
							toast(res.msg)
						}
					}).catch((err) => {
						console.log(err);
					});
				}
			},
			// 打开地图
			to_map(index) {
				var iLocationCode = this.orderList[index].iLocationCode.split(',');
				var latitude = Number(iLocationCode[0]);
				var longitude = Number(iLocationCode[1]);
				var add = this.orderList[index].iAddress;
				uni.openLocation({
					latitude: longitude,
					longitude: latitude,
					name: '客户维修地址',
					address: add
				});
			},

			distance(la1, lo1, la2, lo2) {
				//计算距离
				var La1 = (la1 * Math.PI) / 180.0;
				var La2 = (la2 * Math.PI) / 180.0;
				var La3 = La1 - La2;
				var Lb3 = (lo1 * Math.PI) / 180.0 - (lo2 * Math.PI) / 180.0;
				var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(La3 / 2), 2) + Math.cos(La1) * Math.cos(La2) * Math.pow(Math
					.sin(Lb3 / 2), 2)));
				s = s * 6378.137; //地球半径
				s = Math.round(s * 10000) / 10000;
				s = s.toFixed(2);
				return s;
			},
			bindChange(e) {
				this.currentTab = e.detail.current
			},
		},
		// 下拉触底
		scrobottom() {
			this.pageSize += 10 
			const params = {
				keyword: '',
				page: 1,
				pageSize: this.pageSize,
			};
			this.$newapi.getOrderList(params).then((res) => {
				if (res.code == 200) {
					console.log(res);
					this.orderList = res.data.list.filter(item => item.orderStatus == this.currentTab+2)
				} else {
					toast(res.msg)
				}
			}).catch((err) => {
				console.log(err);
			});
		},

		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad(options) {
			var userId = getApp().globalData.userId;
			this.userId = userId
			this.currentTab = options.index - 1
			//判断type值可以在别的页面返回时不改变当前type子模块显示，如果在onShow里判断则不生效
			/* if (getApp().globalData.currentLocation == '') {
				this.currentTab=0
				this.type= ''
			} else {
				var i = getApp().globalData.currentLocation;
				var j = i + 1;
				this.currentTab=i
				this.type= j
			} */
			// 获取全部
			this.type = ''
			const params = {
				keyword: '',
				page: 1,
				pageSize: 10,
			};
			this.$newapi.getOrderList(params).then((res) => {
				if (res.code == 200) {
					console.log(res);
					this.orderList = res.data.list.filter(item => item.orderStatus == this.currentTab+2)
				} else {
					toast(res.msg)
				}
			}).catch((err) => {
				console.log(err);
			});
		},
	};
</script>

<style scoped>
	.scroll-view_H {
		white-space: nowrap;
		width: 100%;
		height: 180rpx;
		position: fixed;
		left: 0;
		top: 0;
		z-index: 1;
		background-color: #ffffff;
	}

	.swich_tab {
		width: 100%;
		height: 180rpx;
		position: absolute;
		top: 100rpx;
	}

	.scroll-view-item_H {
		display: inline-block;
		width: 25%;
		box-sizing: border-box;
		height: 80rpx;
	}

	.scroll-view-item_H view {
		width: 60%;
		height: 50rpx;
		font-size: 30rpx;
		text-align: center;
		line-height: 50rpx;
		margin-top: 10rpx;
		margin-left: auto;
		margin-right: auto;
	}

	.on {
		color: #3057be;
		border-bottom: 3px solid #3057be;
	}

	.search {
		width: 100%;
		height: 100rpx;
		background-color: #fff;
		position: absolute;
		top: 0;
		padding-top: 15rpx;
	}

	.search_content {
		width: 95%;
		height: 70rpx;
		margin-left: auto;
		margin-right: auto;
		border: 1px solid #3057be;
		border-radius: 50rpx;
	}

	.search_content_center {
		width: 92%;
		height: 100%;
		margin: 0 auto;
		display: flex;
		flex-direction: row;
	}

	.search_logo {
		width: 50rpx;
		height: 100%;
	}

	.search_logo image {
		width: 40rpx;
		height: 40rpx;
		margin-top: 15rpx;
	}

	.search_input {
		width: 90%;
		height: 100%;
	}

	.scrollSpase {
		width: 100%;
		height: 80rpx;
	}

	.weui-input {
		width: 100%;
		height: 100%;
		line-height: 70rpx;
		color: black;
		font-size: 26rpx;
	}

	.phcolor {
		color: #a2a2a2;
	}

	/*选项卡内容部分*/
	.swiper-box {
		width: 100%;
		height: 100%;
		margin-top: 180rpx;
		/* padding-top: 20rpx; */
		background-color: #f2f2f2;
	}

	.swip {
		overflow: auto;
	}

	.type_item {
		width: 95%;
		background-color: white;
		margin: 30rpx auto;
		border-radius: 30rpx;
	}

	.item_title {
		width: 90%;
		height: 100rpx;
		display: flex;
		flex-direction: row;
		margin-left: auto;
		margin-right: auto;
		border-bottom: 1px solid #e2e2e2;
	}

	.item_title view:nth-child(1) {
		width: 20%;
		height: 100%;
		font-size: 30rpx;
		color: #a2a2a2;
		line-height: 100rpx;
		text-align: left;
	}

	.item_title view:nth-child(2) {
		width: 80%;
		height: 100%;
		font-size: 30rpx;
		color: #a2a2a2;
		line-height: 100rpx;
		text-align: left;
	}

	.item_title view:nth-child(3) {
		width: 30%;
		height: 100%;
		font-size: 28rpx;
		line-height: 105rpx;
		text-align: right;
		color: rgb(175, 175, 175);
	}

	.item_operation {
		width: 90%;
		/* height: 180rpx; */
		display: flex;
		flex-direction: row;
		margin-left: auto;
		margin-right: auto;
	}

	.item_img {
		width: 25%;
		height: 100%;
	}

	.item_img image {
		width: 100%;
		height: 140rpx;
		margin-top: 30rpx;
	}

	.item_content {
		width: 100%;
		height: 100%;
	}

	.item_info {
		width: 100%;
		/* height: 140rpx; */
		margin-top: 30rpx;
	}

	.name {
		width: 100%;
		height: 35rpx;
	}

	.name_content {
		width: 95%;
		height: 100%;
		margin: 0 auto;
		display: flex;
		flex-direction: row;
	}

	.name_content view:nth-child(1) {
		width: auto;
		height: 100%;
		color: #a2a2a2;
		text-align: left;
		font-size: 28rpx;
	}

	.name_content view:nth-child(2) {
		width: 50%;
		height: 100%;
		color: black;
		text-align: left;
		font-size: 28rpx;
	}

	.describe {
		width: 100%;
		/* height: 105rpx; */
	}

	.describe_content {
		width: 95%;
		height: 100%;
		margin: 0 auto;
		display: flex;
	}

	.describe_content view:nth-child(1) {
		width: 100%;
		height: 35rpx;
		color: #a2a2a2;
		text-align: left;
		font-size: 28rpx;
		margin-top: 10rpx;
		line-height: 40rpx;
	}

	.describe_content view text {
		color: black;
		font-size: 28rpx;
	}

	.order_adress {
		width: 90%;
		height: 100rpx;
		margin: 0 auto;
		display: flex;
		flex-direction: row;
		border-bottom: 1px solid #f2f2f2;
	}

	.order_adress_text {
		width: 80%;
		height: 100%;
		display: flex;
		flex-direction: row;
	}

	.order_adress_text view:nth-child(1) {
		width: 36rpx;
		height: 36rpx;
		margin-top: 32rpx;
	}

	.order_adress_text view:nth-child(1) image {
		width: 36rpx;
		height: 36rpx;
	}

	.order_adress_text view:nth-child(2) {
		width: 80%;
		height: 100%;
		font-size: 26rpx;
		color: #6e81f3;
		line-height: 100rpx;
		text-align: left;
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
	}

	.order_adress_distance {
		width: 30%;
		height: 100%;
		font-size: 24rpx;
		color: #6e81f3;
		line-height: 100rpx;
		text-align: right;
	}

	.item_btn {
		width: 90%;
		height: 100rpx;
		margin: 0 auto;
	}

	.item_btn view {
		width: 28%;
		height: 60rpx;
		margin-top: 20rpx;
		float: right;
		color: #ffffff;
		background: linear-gradient(to right, #6e81f3, #3057be);
		font-size: 24rpx;
		line-height: 60rpx;
		text-align: center;
		border-radius: 20rpx;
	}

	.not_yet {
		display: flex;
		justify-content: center;
    margin-top: 30%;
	}

	.not_yet image {
		width: 400rpx;
		height: 400rpx;
	}

	@media (min-width: 768px) {
		.search_logo image {
			width: 35rpx;
			height: 35rpx;
		}
	}
</style>